package cn.matrix42.potoo.format.markdown.element.text.title;

import java.util.ArrayList;
import java.util.List;

import cn.matrix42.potoo.format.markdown.element.MarkdownElement;
import cn.matrix42.potoo.lang.Preconditions;
import cn.matrix42.potoo.lang.StringUtils;

public class Heading extends MarkdownElement {

    private final int level;
    private final String content;

    public Heading(int level, String content) {
        Preconditions.checkArgument(level > 0 && level < 7);
        this.level = level;
        this.content = content;
    }

    public Heading(int level) {
        this(level, "");
    }

    public int getLevel() {
        return level;
    }

    public String getContent() {
        return content;
    }

    @Override
    public List<String> toMarkdownStringList() {
        List<String> list = new ArrayList<>();
        list.add(StringUtils.repeat('#', level) + " " + content);
        list.add(context.getConfig().getEof());
        return list;
    }

    public static Heading of(int level, String content) {
        return new Heading(level, content);
    }

    public static Heading of(int level) {
        return new Heading(level);
    }
}
